package com.haier.controller;
import com.alibaba.druid.pool.xa.DruidXADataSource;
import com.haier.pojo.ClassRoom;
import com.haier.pojo.Student;
import com.haier.service.ClassRoomService;
import com.haier.service.StudentService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class TestController {

    @Resource
    private ClassRoomService classRoomService;
    @Resource
    private StudentService studentService;


    @RequestMapping(value = "/test1")
    public ClassRoom gettest1(Integer id){
        return classRoomService.selectClassRoom(id);
    }

    @RequestMapping(value = "/test2")
    public Student gettest2(Integer id){
        return studentService.selectStudent(id);
    }

    /**
     * 事务测试 分布式
     * @param name
     * @return
     */
    @RequestMapping(value = "/insStudent")
    public Integer insStudent(String name){
        Student student= new Student();
        student.setName(name);
        return studentService.insertStudent(student);
    }

    /**
     * 事务测试  单一
     * @param name
     * @return
     */
    @RequestMapping(value = "/insCR")
    public Integer insCR(String name){
        ClassRoom classRoom = new ClassRoom();
        classRoom.setName(name);
        return classRoomService.insClassRoom(classRoom);
    }

}
